package com.wxp.cloud.stream.enums;

import lombok.Getter;

/**
 * 消息标签枚举类
 *
 * @author wxp
 * @version 1.0
 * @description: 消息标签枚举类
 * @date 2022-12-27 15:20
 */
@Getter
public enum MessageTagEnum {

    /**
     * 消息标签
     */
    TAG_A(0, "TagA", "标签A"),
    TAG_B(1, "TagB", "标签B"),
    TAG_C(2, "TagC", "标签C"),
    TAG_D(3, "TagD", "标签D"),
    TAG_E(4, "TagE", "标签E");


    private MessageTagEnum(Integer index, String code, String name) {
        this.index = index;
        this.code = code;
        this.name = name;
    }

    private Integer index;
    private String code;
    private String name;

    /**
     * 通过编码获取枚举
     *
     * @param code 编码
     * @return 枚举
     */
    public static MessageTagEnum getEnumByCode(String code) {
        for (MessageTagEnum tagEnum : MessageTagEnum.values()) {
            if (tagEnum.code.equals(code)) {
                return tagEnum;
            }
        }
        return null;
    }

    /**
     * 通过索引获取编码
     *
     * @param index 索引
     * @return 编码
     */
    public static String getCodeByIndex(Integer index) {
        for (MessageTagEnum tagEnum : MessageTagEnum.values()) {
            if (tagEnum.index.equals(index)) {
                return tagEnum.getCode();
            }
        }
        return "";
    }

}
